import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.List;
import java.util.Random;
/**
 * Write a description of class PipeLines here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class PipeLines extends MiniGame
{
    /*
     * Number of tiles horizontal 
     */
    private int TilesX = 7;
    /*
     * Number of tiles vertical
     */
    private int TilesY = 5;
    
    /*
     * Calculate amount of tiles
     */
    private int TileCount = (TilesX * TilesY);
    
    /*
     * Calculate tile width
     */
    private int TileWidth = ((getWidth() - 100) / TilesX);
    
    /*
     * Calculate tile height
     */
    private int TileHeight = ((getHeight()-100) / TilesY);
    
    
     /*
     * Set counter for new row
     */
    private int b = 0;
    
    private int width = 0;
    private int height = 100+(TileHeight/2);
    
    private String g = "";
    
    /**
     * Constructor for objects of class PipeLines.
     * 
     */
    public PipeLines()
    {    
        super(240, 4);
        populate();
        
    }
    
    public void populate()
    {
        
        /*
         * Set TileObjects Array 
         */
        TileBackground[] TileBackgroundArray = new TileBackground[TileCount];
        

        
        /*
         * Fill background with tiles
         */
        for(int i=0; i < TileCount; i++)
        {
            /*
             * X position of tile
             */
            
            if(b == TilesX) {
                height = (height + TileHeight);
                b = 0;
            }
            TileBackgroundArray[i] = new TileBackground(TileWidth, TileHeight);
            addObject(TileBackgroundArray[i], ((TileWidth / 2) + (TileWidth * b)), height);
            b++;
        }
        
        /*
         * Set reset button
         */
        Reset reset = new Reset();
        addObject(reset, 700, 75);
        
        
        /*
         * Set Start Pipe
         */
        StartPipe sp1 = new StartPipe(TileWidth, TileHeight - 30);
        addObject(sp1, 50, 65);
        
        /*
         * Set End Drain
         */
        EndDrain ed1 = new EndDrain(TileWidth, TileHeight);
        addObject(ed1, 750, 550);
        
        /*
         * Set PipeLines Straight
         */
        PipeLineStraight[] PipeLineStraightArray = new PipeLineStraight[19];
        /*
         * Set PipeLines Curved Array
         */
        PipeLineCurved[] PipeLineCurvedArray = new PipeLineCurved[19];
        
        /*
         * set random rotation
         */
        int n [] = {0, 90, 180, 270};
        Random random = new Random();
        
        int g = 0;
        for(int i = 0; i < 19; i++) 
        {
            g = n[Greenfoot.getRandomNumber(4)]; 
            PipeLineStraightArray[i] = new PipeLineStraight(TileWidth, TileHeight);
            PipeLineCurvedArray[i] = new PipeLineCurved(TileWidth, TileHeight);
            PipeLineStraightArray[i].setRotation(g);
            PipeLineCurvedArray[i].setRotation(g);
        }

        
        /*
         * add pipeline curved objects
         */
        addObject(PipeLineStraightArray[0], 150, 150);
        addObject(PipeLineStraightArray[1], 350, 150);
        addObject(PipeLineStraightArray[2], 650, 550);
        addObject(PipeLineStraightArray[3], 650, 150);
        addObject(PipeLineStraightArray[4], 50, 250);
        addObject(PipeLineStraightArray[5], 350, 250);
        addObject(PipeLineStraightArray[6], 550, 250);
        addObject(PipeLineStraightArray[7], 650, 350);
        addObject(PipeLineStraightArray[8], 350, 350);
        addObject(PipeLineStraightArray[9], 550, 350);
        addObject(PipeLineStraightArray[10], 150, 450);
        addObject(PipeLineStraightArray[12], 250, 450);
        addObject(PipeLineStraightArray[13], 50, 550);
        addObject(PipeLineStraightArray[14], 150, 550);
        addObject(PipeLineStraightArray[15], 450, 550);
        //addObject(ps17, 650, 550);
        addObject(PipeLineStraightArray[17], 250, 250);
        /*
         * add pipeline straight objects
         */
        addObject(PipeLineCurvedArray[0], 50, 150);
        addObject(PipeLineCurvedArray[1], 250, 150);
        addObject(PipeLineCurvedArray[2], 550, 150);
        addObject(PipeLineCurvedArray[3], 150, 250);
        addObject(PipeLineCurvedArray[4], 650, 450);
        addObject(PipeLineCurvedArray[5], 450, 250);
        addObject(PipeLineCurvedArray[6], 650, 250);
        addObject(PipeLineCurvedArray[7], 50, 350);
        addObject(PipeLineCurvedArray[8], 250, 350);
        addObject(PipeLineCurvedArray[9], 150, 350);
        addObject(PipeLineCurvedArray[10], 450, 350);
        addObject(PipeLineCurvedArray[11], 50, 450);
        addObject(PipeLineCurvedArray[12], 350, 450);
        addObject(PipeLineCurvedArray[13], 450, 450);
        addObject(PipeLineCurvedArray[14], 550, 450);
        addObject(PipeLineCurvedArray[15], 250, 550);
        addObject(PipeLineCurvedArray[16], 350, 550);
        addObject(PipeLineCurvedArray[17], 550, 550);
        addObject(PipeLineCurvedArray[18], 450, 150);        
    }
}
